home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / ggraph / RCS / hist.c,v < prev    next >
Text File  |  1989-07-12  |  4KB  |  156 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     89.07.12.01.40.53;  author douglis;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @baseline from monet (?)
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @#include <stdio.h>
  27. #include <errno.h>
  28. #include <strings.h>
  29. #include <math.h>
  30. #include "ggraph.h"
  31. #include "ggraphdefs.h"
  32. /****************************************************************
  33.  *                                *
  34.  *    hist - write the points of a histogramn            *
  35.  *                                *
  36.  ****************************************************************/
  37. hist ()
  38. {
  39.     register int     i;
  40.     register float llabxl, llabyl;
  41.     register float prevx, prevy;
  42.     int clipped = 0;
  43.  
  44.     prevx = prevy = 0.0;    /* init values first */
  45.     for (curline = 0; ((curline != cg.maxlines) && (cl != NULL)); ++curline) {
  46.     if (cl->lonoff) {
  47.     /* connect the dots */
  48.         if(cl->ctype){
  49.         fprintf (outfile, "%d\n", cl->ctype);
  50.             prevx = ((0.0 - cg.xoffset) * cg.scalex) + cg.xorigin;
  51.             prevy = ((0.0 - cg.yoffset) * cg.scaley) + cg.yorigin;
  52.         fprintf (outfile, "%4.1f %4.1f\n", prevx, prevy);
  53.         graphy = ((cl->ypoints[0] - cg.yoffset) * cg.scaley)
  54.           + cg.yorigin;
  55.         if((graphy < 0.0)||(graphy > 512.0) || 
  56.         (prevx < 0.0)||(prevx > 512.0))
  57.           fprintf(stderr,"Point out of range\n");
  58.         else
  59.         if((graphy < cg.yorigin)||(graphy > cg.yplotmax) || 
  60.               (prevx < cg.xorigin)||(prevx > cg.xplotmax)) {
  61.                 fprintf(stderr,"%s:Point off graph clipped\n", 
  62.                    graphname);
  63.                 fprintf(outfile, 
  64.                        (version == SUN_GREMLIN) ?
  65.                        "*\n" : "-1.00 -1.00\n");
  66.                 fprintf (outfile, "%d %d\n%d\n", cl->ltype, 0, 0);
  67.                 fprintf (outfile, "%d\n", cl->ctype);
  68.             } 
  69.         else
  70.             fprintf (outfile, "%4.1f %4.1f\n", prevx, graphy);
  71.         prevx = ((cl->xpoints[0] - cg.xoffset) * cg.scalex)
  72.           + cg.xorigin;
  73.         for (i = 0; i < cl->maxpoint; i++) {
  74.             graphx = ((cl->xpoints[i] - cg.xoffset) * cg.scalex)
  75.               + cg.xorigin;
  76.         graphy = ((cl->ypoints[i] - cg.yoffset) * cg.scaley)
  77.           + cg.yorigin;
  78.         if((graphx < 0.0)||(graphx > 512.0) || 
  79.         (prevy < 0.0)||(prevy > 512.0))
  80.             fprintf(stderr,"Point out of range\n");
  81.         else
  82.             if((graphy < cg.yorigin)||(graphy > cg.yplotmax) || 
  83.               (prevx < cg.xorigin)||(prevx > cg.xplotmax)) {
  84.                 fprintf(stderr,"%s:Point off graph clipped\n", 
  85.                    graphname);
  86.                 if (!clipped) {
  87.                     fprintf(outfile, 
  88.                        (version == SUN_GREMLIN) ?
  89.                        "*\n" : "-1.00 -1.00\n");
  90.                     fprintf (outfile, "%d %d\n%d\n",
  91.                         cl->ltype, 0, 0);
  92.                     clipped = 1;
  93.                 } 
  94.             } 
  95.             else {
  96.                 if (clipped) {
  97.                     fprintf (outfile, "%d\n", cl->ctype);
  98.                     clipped = 0;
  99.                 } 
  100.                 fprintf (outfile, "%4.1f %4.1f\n", prevx, graphy);
  101.             } 
  102.         if((graphy < 0.0)||(graphy > 512.0) || 
  103.         (graphx < 0.0)||(graphx > 512.0))
  104.             fprintf(stderr,"Point out of range\n");
  105.         else
  106.             if((graphy < cg.yorigin)||(graphy > cg.yplotmax) || 
  107.               (graphx < cg.xorigin)||(graphx > cg.xplotmax)) {
  108.                 fprintf(stderr,"%s:Point off graph clipped\n", 
  109.                    graphname);
  110.                 if (!clipped) {
  111.                     fprintf(outfile, 
  112.                        (version == SUN_GREMLIN) ?
  113.                        "*\n" : "-1.00 -1.00\n");
  114.                     fprintf (outfile, "%d %d\n%d\n", 
  115.                         cl->ltype, 0, 0);
  116.                     clipped = 1;
  117.                 } 
  118.             } 
  119.             else {
  120.                 if (clipped) {
  121.                     fprintf (outfile, "%d\n", cl->ctype);
  122.                     clipped = 0;
  123.                 } 
  124.                 fprintf (outfile, "%4.1f %4.1f\n", graphx, graphy);
  125.             } 
  126.         prevx = graphx;
  127.         prevy = graphy;
  128.         }
  129.             prevy = ((0.0 - cg.yoffset) * cg.scaley) + cg.yorigin;
  130.         fprintf (outfile, "%4.1f %4.1f\n", prevx, prevy);
  131.         fprintf(outfile, (version == SUN_GREMLIN) ? "*\n" : "-1.00 -1.00\n");
  132.         fprintf (outfile, "%d %d\n%d\n", cl->ltype, 0, 0);
  133.         }
  134.         if (cl->llabsw) {
  135.         if(cl->llabel.t_text[0] == NULL)
  136.             strcpy (cl->llabel, cl->lname);
  137.         if(!cl->llabel.t_xpos)
  138.             llabxl = (cl->xpoints[cl->maxpoint-1] * cg.scalex)
  139.              + cg.xorigin - 10.0;
  140.         else
  141.             llabxl = (cl->llabel.t_xpos * cg.scalex) + cg.xorigin - 10.0;
  142.         if(!cl->llabel.t_ypos)
  143.             llabyl = (cl->ypoints[cl->maxpoint-1] * cg.scaley)
  144.              + cg.yorigin + 5.0;
  145.         else
  146.             llabyl = (cl->llabel.t_ypos * cg.scaley)
  147.             + cg.yorigin + 5.0;
  148.         drawctext (llabxl, llabyl, cl->llabel.t_font, cl->llabel.t_size,
  149.           cl->llabel.t_text, TOPCENTER_TEXT);
  150.         }
  151.     }
  152.     }
  153. }
  154.  
  155. @
  156.